<template>
	<view class="studentDetail">
		<view class="title">
			<u-icon name="arrow-left" size="24" @click="back"></u-icon>
			<text style="margin-left: 24rpx;">学生详情</text>
		</view>

		<view class="studentmessage">
			<view class="boxitem">
				<view class="itemleft">
					<view class="avaterbox">
						<image class="avatartimg" :src="studentDetail.photos.url"></image>
					</view>
					<view class="nameandmessage">
						<view class="name">
							{{studentDetail.name}}
						</view>
						<view class="message">
							{{studentDetail.school}}/{{studentDetail.speciality}}
						</view>
					</view>
				</view>

				<view class="itemright">
					<view class="baokao">
						报考：
					</view>
					<view class="zhuanye">
						{{studentDetail.science_id_text}}
					</view>
				</view>
			</view>

			<view class="messagedetail">
				<view class="iphnumbox">
					<view class="iphnumtext">
						手机号码
					</view>
					<view class="content">
						{{studentDetail.mobile}}
					</view>
				</view>
				<view class="iphnumbox">
					<view class="iphnumtext">
						电子邮箱
					</view>
					<view class="content">
						{{studentDetail.mailbox}}
					</view>
				</view>
				<view class="iphnumbox">
					<view class="iphnumtext">
						考研成绩
					</view>
					<view class="content">
						{{studentDetail.achievement}}
					</view>
				</view>
				<view class="iphnumbox">
					<view class="iphnumtext">
						感兴趣的研究方向
					</view>
					<view class="content">
						{{studentDetail.direction}}
					</view>
				</view>
			</view>

		</view>


		<view class="fujian">
			<view class="fujiantext">
				附件
			</view>
			<view class="fujianbox">
				<view class="fujianitem" v-for="(item,index) in fujiandata" @click="handlexiazai(item)">
					<view class="imgbox">
						<image class="" style="width: 100%; height: 100%;" src="../../static/image/files.png"></image>
					</view>
					<view class="fileName">
						{{item.name}}
					</view>
					<view class="imgbox">
						<image class="" style="width: 100%; height: 100%;" src="../../static/image/download.png"
							></image>
					</view>
				</view>
			</view>
		</view>

		<!-- <view class="bottom">

		</view> -->

	</view>
</template>

<script>
	import {
		getStudentDetail
	} from "@/api/api.js"
	export default {
		data() {
			return {
				studentDetail: {},
				fujiandata: [],
			}
		},
		onLoad(options) {
			console.log("options", options)
			this.getStudentDetails(options.id)
		},
		methods: {
			async getStudentDetails(id) {
				let res = await getStudentDetail({
					student_id: id
				})
				if (res.code == 1) {
					console.log("学生详情", res)
					this.studentDetail = res.data
					console.log("附件", this.studentDetail.annex)
					this.fujiandata = this.studentDetail.annex
				}
			},
			handlexiazai(item){
				let that = this
				uni.showModal({
					// title: '提示',
					content: '确定下载并查看附件吗？',
					confirmColor: '#4A9CFF',
					success: async function(res) {
						console.log("是否选择", res)
						if (res.confirm) {
							that.xiazaiFujian(item)
						}
					}
				})
			},
			xiazaiFujian(item) {
				let that = this
				uni.downloadFile({
					url: item.url, //仅为示例，并非真实的资源
					success: (res) => {
						if (res.statusCode === 200) {
							console.log('下载成功', res);
							let fileType = that.getfileName(res.tempFilePath)
							uni.openDocument({
								// 文件路径
								filePath: res.tempFilePath,
								// 文件类型 除图片以外文件都需要文件类型  
								//有效值为  doc, xls, ppt, pdf, docx, xlsx, pptx
								fileType: fileType,
								//是否开启转发 
								showMenu: true,
							})

						}
					}
				});
			},
				getfileName(filename) {
							// 转换为小写方便处理 拿到.的下标
							const pos = filename.toLowerCase().lastIndexOf('.')
							let suffix = ''
							// 判断是否是文件或图片
							if (pos !== -1) {
								// 拿到截取.的下标后面所有字符(这样就拿到了文件类型)
								suffix = filename.substring(pos+1)
							}
							return suffix
						},
		
			back() {
				uni.navigateBack({
					delta: 1
				});
			}
		}

	}
</script>

<style scoped lang="scss">
	.studentDetail {
		min-height: 100%;
		background: #F7F8FA;

		.title {
			width: 100%;
			height: 176rpx;
			padding-top: 110rpx;
			box-sizing: border-box;
			background: #ffffff;
			display: flex;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
			line-height: 38rpx;
			padding-left: 34rpx;
			box-sizing: border-box;

		}

		.studentmessage {
			width: 100%;
			// height: 866rpx;
			background: #ffffff;

			.boxitem {
				width: 690rpx;
				height: 164rpx;
				background: #FFFFFF;
				border-radius: 30rpx 30rpx 30rpx 30rpx;
				display: flex;
				justify-content: space-between;
				padding: 30rpx;
				box-sizing: border-box;

				.itemleft {
					display: flex;

					.avaterbox {
						.avatartimg {
							margin-right: 10rpx;
							width: 104rpx;
							height: 104rpx;
							border-radius: 100rpx;
						}
					}

					.nameandmessage {
						padding-top: 5rpx;
						box-sizing: border-box;

						.name {
							font-size: 32rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #333333;
							line-height: 38rpx;
						}

						.message {
							font-size: 26rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #666666;
							line-height: 30rpx;
							margin-top: 20rpx;
						}
					}

				}

				.itemright {
					display: flex;
					align-items: center;
					flex-direction: column;
					justify-content: space-between;

					.baokao {
						font-size: 26rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						line-height: 30rpx;
					}

					.zhuanye {
						height: 48rpx;
						background: #F0F7FF;
						border-radius: 12rpx 12rpx 12rpx 12rpx;
						opacity: 1;
						border: 2rpx solid #4A9CFF;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #4A9CFF;
						line-height: 28rpx;
						text-align: center;
						line-height: 48rpx;
						padding: 0 7rpx;

					}
				}
			}

			.messagedetail {
				padding: 30rpx;
				padding-top: 0;
				box-sizing: border-box;

				.iphnumbox {
					margin: 60rpx 0;

					.iphnumtext {
						font-size: 32rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
						line-height: 38rpx;
					}

					.content {
						font-size: 32rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: bold;
						color: #333333;
						line-height: 38rpx;
						margin-top: 20rpx;
					}
				}
			}
		}

		.fujian {
			padding: 30rpx;

			// margin-top: 30rpx;
			.fujiantext {
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 38rpx;
			}

			.fujianbox {
				margin-top: 30rpx;

				.fujianitem {
					width: 100%;
					height: 124rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					background-color: pink;
					padding: 30rpx;
					box-sizing: border-box;
					background: #FFFFFF;
					border-radius: 20rpx 20rpx 20rpx 20rpx;

					.fileName {
						width: 500rpx;
						font-size: 32rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #333333;
						line-height: 38rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}

					.imgbox {
						width: 48rpx;
						height: 48rpx;
					}
				}

			}
		}

		.bottom {
			width: 100%;
			height: 180rpx;
			background-color: #ffffff;
			position: fixed;
			bottom: 0;
		}

	}
</style>